home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
DELPHI32
/
SEARCH
/
RUBICON
/
RBMAIN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-10-21
|
46KB
|
1,588 lines
{*********************************************************}
{* RBMAIN.PAS 1.20 *}
{* Copyright (c) Tamarack Associates 1996. *}
{* All rights reserved. *}
{*********************************************************}
{$I TARUBICN.INC}
{$B-} {* Boolean evaluation *}
{$G+} {* Generate 286 code *}
{$X+} {* eXtended syntax *}
unit rbMain;
interface
uses
{$IFDEF WIN32}
Windows,
PrevInst,
{$ELSE}
WinTypes, WinProcs,
{$ENDIF}
SysUtils, Messages, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, TabNotBk, DB, DBTables, Menus, Gauges, ExtCtrls,
{$IFDEF WIN32}
ComCtrls,
{$ENDIF}
{$IFDEF HaveSysTools}
StUtils,
{$ELSE}
taTools,
{$ENDIF}
taRubicn, taLink,
rbDBGrid, rbLink, rbPhase, rbAbout;
type
TSearchProc = PROCEDURE(Find : STRING) OF OBJECT;
TPage = (pgIntroduction,pgTable,pgBuild,pgSearch);
TPages = SET OF TPage;
TMainForm = class(TForm)
TabbedNotebook1: TTabbedNotebook;
KeyViolTable1: TTable;
KeyViolDataSource: TDataSource;
MatchTable1: TTable;
MatchDataSource: TDataSource;
SearchTable1: TTable;
SearchDataSource: TDataSource;
WordsTable1: TTable;
WordsDataSource: TDataSource;
MakeDictionary1: TMakeDictionary;
SearchDictionary1: TSearchDictionary;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
{* Intro Tab *}
RubiconLabel: TLabel;
EngineLabel: TLabel;
CopyrightLabel: TLabel;
PrevBtn: TButton;
NextBtn: TButton;
StatusPanel: TPanel;
MOMemo: TMemo;
{* Table Tab *}
TableGroupBox: TGroupBox;
AliasLabel: TLabel;
AliasComboBox: TComboBox;
TableLabel: TLabel;
TableComboBox: TComboBox;
IndexLabel: TLabel;
IndexComboBox: TComboBox;
FieldsGroupBox: TGroupBox;
AvailLabel: TLabel;
AvailFldListBox: TListBox;
SelectFldListBox: TListBox;
SelectLabel: TLabel;
MoveRightBtn: TButton;
MoveLeftBtn: TButton;
AddLinkBtn: TButton;
EditLinkBtn: TButton;
{* Build Tab *}
StatsGroupBox: TGroupBox;
StatElapsedLabel: TLabel;
StatWordLabel: TLabel;
StatMemLabel: TLabel;
StatMaxMemLabel: TLabel;
StatTableLabel: TLabel;
StatBlobLabel: TLabel;
StatCompressLabel: TLabel;
BuildTimeLabel: TLabel;
WordCountLabel: TLabel;
MemUsedLabel: TLabel;
MaxMemLabel: TLabel;
DBSizeLabel: TLabel;
MBSizeLabel: TLabel;
CompressionLabel: TLabel;
BuildBtn: TButton;
BuildOptionsRadioGroup: TRadioGroup;
BuildNotebook: TNotebook;
TablesGroupBox: TGroupBox;
WordsLabel: TLabel;
KeyViolLabel: TLabel;
WordsEdit: TEdit;
KeyViolEdit: TEdit;
FileCompressionCheckBox: TCheckBox;
WordDelimGroupBox: TGroupBox;
DelimsEdit: TEdit;
IndexModeGroupBox: TGroupBox;
IndexModeComboBox: TComboBox;
StrictCheckingCheckBox: TCheckBox;
OtherGroupBox: TGroupBox;
MinWordLenLabel: TLabel;
RecordLimitLabel: TLabel;
MemoryLimitLabel: TLabel;
MinWordLenEdit: TEdit;
RecordLimitEdit: TEdit;
MemoryComboBox: TComboBox;
AltMemMgrCheckBox: TCheckBox;
{* Search Tab *}
SearchForGroupBox: TGroupBox;
SearchComboBox: TComboBox;
SearchBtn: TButton;
SearchResultsGroupBox: TGroupBox;
WordsBtn: TButton;
RecordsBtn: TButton;
ElapsedTimeLabel: TLabel;
SearchOptionsRadioGroup: TRadioGroup;
SearchNotebook: TNotebook;
SearchLogicRadioGroup: TRadioGroup;
SearchModeRadioGroup: TRadioGroup;
SearchModeMemo : TMemo;
RankModeRadioGroup: TRadioGroup;
RankModeMemo: TMemo;
SubFieldsGroupBox: TGroupBox;
SubFieldsAddAllBtn: TButton;
SubFieldsRemoveBtn: TButton;
SubFieldListBox: TListBox;
CachingGroupBox: TGroupBox;
CacheMemLimitLabel: TLabel;
CacheMemoryLimitEdit: TEdit;
CachingDiskReadsLabel: TLabel;
CachingCacheReadsLabel: TLabel;
CachingMemoryUsageLabel: TLabel;
CachingSourceReadsLabel: TLabel;
DiskReadsLabel: TLabel;
CacheReadsLabel: TLabel;
SourceReadsLabel: TLabel;
MemoryUsageLabel: TLabel;
ResetBtn: TButton;
FlushBtn: TButton;
MatchedWordsGroupBox: TGroupBox;
MatchingWordsListBox: TListBox;
MatchingWordsMemo: TMemo;
SearchOtherGroupBox: TGroupBox;
MatchTableLabel: TLabel;
MatchedEdit: TEdit;
MatchRecordLimitLabel: TLabel;
MatchRecordLimitEdit: TEdit;
AnyCharLabel: TLabel;
AnyCharEdit: TEdit;
OneCharLabel: TLabel;
OneCharEdit: TEdit;
NearWordLabel: TLabel;
NearWordEdit: TEdit;
{* Menus *}
MainMenu1: TMainMenu;
File1: TMenuItem;
NewMenuItem: TMenuItem;
OpenMenuItem: TMenuItem;
SaveMenuItem: TMenuItem;
SaveAsMenuItem: TMenuItem;
ExitMenuItem: TMenuItem;
View1: TMenuItem;
SearchTableMenuItem: TMenuItem;
WordsTableMenuItem: TMenuItem;
MatchTableMenuItem: TMenuItem;
KeyViolTableMenuItem: TMenuItem;
BreakMenuItem: TMenuItem;
ShowAllFieldsMenuItem: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
Contents1: TMenuItem;
ShowHintsMenuItem: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure NextBtnClick(Sender: TObject);
procedure PrevBtnClick(Sender: TObject);
procedure TabbedNotebook1Click(Sender: TObject);
procedure TabbedNotebook1Change(Sender: TObject; NewTab: Integer;
var AllowChange: Boolean);
procedure IntegerEditExit(Sender: TObject);
procedure MakeDictionary1PhaseOne(Sender: TObject);
procedure MakeDictionary1PhaseTwo(Sender: TObject);
{* Table Tab *}
procedure AliasComboBoxChange(Sender: TObject);
procedure TableComboBoxChange(Sender: TObject);
procedure IndexComboBoxChange(Sender: TObject);
procedure MoveRightBtnClick(Sender: TObject);
procedure MoveLeftBtnClick(Sender: TObject);
procedure AddLinkBtnClick(Sender: TObject);
procedure EditLinkBtnClick(Sender: TObject);
procedure AvailFldListBoxClick(Sender: TObject);
{* Build Tab *}
procedure BuildBtnClick(Sender: TObject);
procedure IndexModeComboBoxChange(Sender: TObject);
procedure BuildOptionsRadioGroupClick(Sender: TObject);
procedure KeyViolEditExit(Sender: TObject);
procedure WordsEditExit(Sender: TObject);
procedure MatchedEditExit(Sender: TObject);
{* Search Tab *}
procedure AnyCharEditExit(Sender: TObject);
procedure SearchBtnClick(Sender: TObject);
procedure SubFieldsAddAllBtnClick(Sender: TObject);
procedure SubFieldsRemoveBtnClick(Sender: TObject);
procedure SubFieldListBoxDblClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure FlushBtnClick(Sender: TObject);
procedure SearchModeRadioGroupClick(Sender: TObject);
procedure WordsBtnClick(Sender: TObject);
procedure RecordsBtnClick(Sender: TObject);
procedure SearchComboBoxChange(Sender: TObject);
procedure SearchOptionsRadioGroupClick(Sender: TObject);
{* Menus *}
procedure SearchTableMenuItemClick(Sender: TObject);
procedure WordsTableMenuItemClick(Sender: TObject);
procedure MatchTableMenuItemClick(Sender: TObject);
procedure NewMenuItemClick(Sender: TObject);
procedure SaveMenuItemClick(Sender: TObject);
procedure SaveAsMenuItemClick(Sender: TObject);
procedure OpenMenuItemClick(Sender: TObject);
procedure ExitMenuItemClick(Sender: TObject);
procedure ShowAllFieldsMenuItemClick(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure ShowHintsMenuItemClick(Sender: TObject);
procedure Contents1Click(Sender: TObject);
procedure WordsTable1AfterOpen(DataSet: TDataset);
procedure SearchTable1CalcFields(DataSet: TDataset);
procedure SearchTable1AfterOpen(DataSet: TDataset);
procedure SearchTable1BeforeClose(DataSet: TDataset);
procedure WordsTable1BeforeClose(DataSet: TDataset);
procedure MatchTable1AfterOpen(DataSet: TDataset);
procedure MatchTable1BeforeClose(DataSet: TDataset);
procedure KeyViolTable1AfterOpen(DataSet: TDataset);
procedure KeyViolTable1BeforeClose(DataSet: TDataset);
procedure KeyViolTableMenuItemClick(Sender: TObject);
procedure SearchDictionary1Search(Sender: TObject);
private
{ Private declarations }
FEditLink : TLinkData;
FFileName : STRING;
FFileNo : INTEGER;
FLinkList : TLinkList;
FLastUpd : LONGINT;
StartTime : TDateTime;
FTableType: TTableType;
FContinue : BOOLEAN;
FPages : TPages;
PROCEDURE SetDefaults1;
PROCEDURE SetDefaults2;
PROCEDURE SetPages(Value : TPages);
PROCEDURE StructureTable(Table : TTable);
PROCEDURE ViewGridForm(DataSource : TDataSource);
PROCEDURE UpdateCacheStats;
PROPERTY Pages : TPages READ FPages WRITE SetPages;
public
{ Public declarations }
PROCEDURE Search;
end;
var
MainForm: TMainForm;
implementation
{.$DEFINE Debug}
{$R *.DFM}
CONST FileSignature = 'Rubicon for Delphi Demo';
FileVersion = $00010010;
RefreshTics = 500;
SearchBtnCaption : ARRAY[TSearchMode] OF STRING[10] = ('Search','Narrow','Widen');
SearchBtnHint : ARRAY[TSearchMode] OF STRING[25] =
('Perform a global search',
'Narrow the search',
'Widen the search');
PROCEDURE SetComboBoxIndex(CB : TComboBox ; S : STRING);
BEGIN
WITH CB DO ItemIndex := Items.IndexOf(S)
END;
FUNCTION FindForm(Caption : STRING) : TForm;
VAR i : INTEGER;
BEGIN
Result := NIL;
WITH Application DO
FOR i := 0 TO ComponentCount - 1 DO
IF (Components[i] IS TForm) AND
(TForm(Components[i]).Caption = Caption) THEN
BEGIN
Result := TForm(Components[i]);
EXIT
END
END;
{* Table must be closed *}
PROCEDURE FixupTable(Table : TTable);
VAR Alias : STRING;
BEGIN
WITH Table DO
BEGIN
Alias := JustAliasName(TableName);
IF Alias <> '' THEN
BEGIN
DatabaseName := Alias;
TableName := COPY(TableName,LENGTH(Alias) + 3,LENGTH(TableName) - LENGTH(Alias) - 2)
END
END
END;
FUNCTION NameChanged(Table : TTable ; NewName : STRING) : BOOLEAN;
VAR Alias : STRING;
BEGIN
Alias := JustAliasName(NewName);
IF Alias = '' THEN Result := CompareText(NewName,Table.TableName) <> 0
ELSE
BEGIN
NewName := COPY(NewName,LENGTH(Alias) + 3,LENGTH(NewName) - LENGTH(Alias) - 2);
Result := (CompareText(Alias,Table.DatabaseName) <> 0) OR
(CompareText(NewName,Table.TableName) <> 0)
END
END;
PROCEDURE UpdateElapsedTime(L : TLabel);
VAR ElapsedTime : LONGINT;
FormatSeconds : STRING[20];
BEGIN
ElapsedTime := GetTickCount - L.Tag;
IF ElapsedTime < 1000 THEN FormatSeconds := '%4.3f seconds'
ELSE
IF ElapsedTime < 10000 THEN FormatSeconds := '%4.2f seconds'
ELSE FormatSeconds := '%4.1f seconds';
L.Caption := Format(FormatSeconds,[ElapsedTime/1000])
END;
{$IFDEF Debug}
{* Used only for testing the OmitList feature *}
PROCEDURE LoadOmits(D : TAbstractDictionary);
VAR T : TTable;
BEGIN
T := TTable.Create(NIL);
TRY
T.TableName := ExtractFilePath(ParamStr(0)) + 'omits.db';
TRY
D.LoadOmitsFromTable(T,'Word')
EXCEPT
END
FINALLY
T.Free
END
END;
{$ENDIF}
procedure TMainForm.FormCreate(Sender: TObject);
begin
{$IFDEF WIN32}
IF DoIExist(Caption) THEN Application.Terminate;
{$ENDIF}
FFileNo := 1;
FLinkList := TLinkList.Create;
SetDefaults1;
SetDefaults2;
Application.ShowHint := TRUE;
Application.HelpFile := ExtractFilePath(ParamStr(0)) + 'demo.hlp';
{$IFNDEF AltMemMgr}
AltMemMgrCheckBox.Enabled := FALSE;
{$ENDIF}
{$IFDEF Debug};
LoadOmits(MakeDictionary1);
{$ENDIF}
end;
PROCEDURE TMainForm.SetDefaults1;
BEGIN
FFileName := 'LINK' + IntToStr(FFileNo) + '.RDM';
Pages := [pgIntroduction,pgTable];
TabbedNotebook1.PageIndex := ORD(pgIntroduction);
TabbedNotebook1Click(TabbedNotebook1);
MemoryComboBox.ItemIndex := 2; {* 8 mega bytes *}
WITH AliasComboBox DO
BEGIN
Session.GetAliasNames(Items);
IF Items.Count > 0 THEN
BEGIN
ItemIndex := 0;
AliasComboBoxChange(NIL)
END
END;
END;
PROCEDURE TMainForm.SetDefaults2;
BEGIN
SearchLogicRadioGroup.ItemIndex := 0;
SearchModeRadioGroup.ItemIndex := 0;
RankModeRadioGroup.ItemIndex := 0;
ResetBtnClick(ResetBtn);
WordsEdit.Text := 'words';
MatchedEdit.Text := 'matched';
KeyViolEdit.Text := 'keyviol';
StrictCheckingCheckBox.Checked := TRUE;
MakeDictionary1.WordDelims := '';
DelimsEdit.Text := DefaultWordDelims;
FileCompressionCheckBox.Checked := TRUE;
MinWordLenEdit.Text := '3';
RecordLimitEdit.Text := '';
AltMemMgrCheckBox.Checked := TRUE;
SearchComboBox.Text := '';
SearchComboBox.Items.Clear;
MatchingWordsListBox.Items.Clear;
CacheMemoryLimitEdit.Text := '100000';
MatchRecordLimitEdit.Text := '100';
NearWordEdit.Text := '8';
AnyCharEdit.Text := '*';
OneCharEdit.Text := '?';
BuildTimeLabel.Caption := '';
WordCountLabel.Caption := '';
MemUsedLabel.Caption := '';
MaxMemLabel.Caption := '';
DBSizeLabel.Caption := '';
MBSizeLabel.Caption := '';
CompressionLabel.Caption := '';
WordsBtn.Caption := 'Words';
RecordsBtn.Caption := 'Records';
ElapsedTimeLabel.Caption := '0.00 Seconds';
FLastUpd := 0;
END;
procedure TMainForm.AliasComboBoxChange(Sender: TObject);
begin
WITH TableComboBox DO
TRY
Session.GetTableNames(AliasComboBox.Items[AliasComboBox.ItemIndex],'',TRUE,FALSE,Items);
IF Items.Count > 0 THEN
BEGIN
ItemIndex := 0;
TableComboBoxChange(NIL)
END
ELSE
BEGIN
AvailFldListBox.Items.Clear;
SelectFldListBox.Items.Clear;
END
EXCEPT
RAISE
END
end;
procedure TMainForm.TableComboBoxChange(Sender: TObject);
begin
WITH SearchTable1 DO
BEGIN
Close;
WordsTable1.Close;
KeyViolTable1.Close;
MatchTable1.Close;
FLinkList.ClearLinks;
SetDefaults2;
WITH AliasComboBox DO
DatabaseName := Items[ItemIndex];
WITH TableComboBox DO
TableName := Items[ItemIndex];
IndexName := '';
WordsTable1.DatabaseName := DatabaseName;
MatchTable1.DatabaseName := DatabaseName;
StructureTable(SearchTable1);
MakeDictionary1.DataSource := NIL;
Open;
FTableType := GetTableType(SearchTable1);
WordsTable1.TableType := FTableType;
MatchTable1.TableType := FTableType;
MakeDictionary1.IndexMode := SafeIndexMode(SearchTable1);
MakeDictionary1.DataSource := SearchDataSource;
IndexComboBox.Clear;
GetIndexNames(IndexComboBox.Items);
GetFieldNames(AvailFldListBox.Items);
MakeDictionary1.IndexMode := SafeIndexMode(SearchTable1);
IndexModeComboBox.ItemIndex := ORD(MakeDictionary1.IndexMode);
MakeDictionary1.DataSource := SearchDataSource; {* Force a reset of FResultBits *}
SelectFldListBox.Items.Clear;
SubFieldListBox.Clear;
Pages := Pages - [pgBuild];
END
end;
procedure TMainForm.IndexComboBoxChange(Sender: TObject);
begin
TRY
WITH IndexComboBox, SearchTable1 DO
IF ItemIndex >= 0 THEN
IndexName := Items[ItemIndex]
ELSE
IndexName := ''
EXCEPT
ON EDatabaseError DO
END
end;
procedure TMainForm.NextBtnClick(Sender: TObject);
begin
WITH TabbedNotebook1 DO PageIndex := PageIndex + 1;
TabbedNotebook1Click(TabbedNotebook1)
end;
procedure TMainForm.PrevBtnClick(Sender: TObject);
begin
WITH TabbedNotebook1 DO PageIndex := PageIndex - 1;
TabbedNotebook1Click(TabbedNotebook1)
end;
procedure TMainForm.MoveRightBtnClick(Sender: TObject);
VAR i : INTEGER;
begin
WITH AvailFldListBox DO
IF SelCount > 0 THEN
FOR i := Items.Count - 1 DOWNTO 0 DO
IF Selected[i] THEN
BEGIN
SelectFldListBox.Items.Add(Items[i]);
IF NOT ShowAllFieldsMenuItem.Checked THEN
SearchTable1.FieldByName(Items[i]).Visible := TRUE;
Items.Delete(i)
END;
IF NOT (pgBuild IN Pages) THEN
IF SelectFldListBox.Items.Count > 0 THEN
BEGIN
Pages := Pages + [pgBuild];
ShowAllFieldsMenuItem.Enabled := TRUE
END
end;
procedure TMainForm.MoveLeftBtnClick(Sender: TObject);
VAR i : INTEGER;
begin
WITH SelectFldListBox DO
IF SelCount > 0 THEN
FOR i := Items.Count - 1 DOWNTO 0 DO
IF Selected[i] THEN
BEGIN
AvailFldListBox.Items.Add(Items[i]);
IF NOT ShowAllFieldsMenuItem.Checked THEN
SearchTable1.FieldByName(Items[i]).Visible := FALSE;
Items.Delete(i)
END;
IF (pgBuild IN Pages) AND
(SelectFldListBox.Items.Count = 0) THEN
BEGIN
Pages := Pages - [pgBuild];
WITH ShowAllFieldsMenuItem DO
BEGIN
Enabled := FALSE;
IF NOT Checked THEN ShowAllFieldsMenuItemClick(ShowAllFieldsMenuItem)
END
END
end;
procedure TMainForm.ViewGridForm(DataSource : TDataSource);
VAR F : TDBGridForm;
GridCaption : STRING;
BEGIN
GridCaption := UpperCase(TTable(DataSource.DataSet).TableName);
F := TDBGridForm(FindForm(GridCaption));
IF F = NIL THEN
BEGIN
Application.CreateForm(TDBGridForm,F);
F.Grid.DataSource := DataSource;
F.Caption := GridCaption;
F.Show
END
ELSE
BEGIN
IF F.WindowState = wsMinimized THEN
F.WindowState := wsNormal;
F.BringToFront
END
END;
procedure TMainForm.SearchTableMenuItemClick(Sender: TObject);
begin
ViewGridForm(SearchDataSource)
end;
procedure TMainForm.BuildBtnClick(Sender: TObject);
CONST MemoryA : ARRAY[0..4] OF INTEGER = (16,12,8,4,2);
begin
{$IFNDEF WIN32}
HeapLimit := 16384;
HeapBlock := {HeapLimit * 8}65535;
{$ENDIF}
Screen.Cursor := crHourGlass;
WITH MakeDictionary1 DO
TRY
WordsTable1.Close;
WordsTable1.TableName := WordsEdit.Text;
FixupTable(WordsTable1);
KeyViolTable1.Close;
KeyViolTable1.TableName := AliasToPath(KeyViolEdit.Text);
FixupTable(MatchTable1);
MatchTable1.Close;
MatchTable1.TableName := MatchedEdit.Text;
FixupTable(MatchTable1);
FieldNames.Assign(SelectFldListBox.Items);
FileCompression := FileCompressionCheckBox.Checked;
MemoryLimit := MemoryA[MemoryComboBox.ItemIndex] * 1048575 {2^20 - 1};
WordDelims := DelimsEdit.Text;
MinWordLen := StrToInt(MinWordLenEdit.Text);
StrictChecking := StrictCheckingCheckBox.Checked;
IndexMode := TIndexMode(IndexModeComboBox.ItemIndex);
KeyViolName := KeyViolEdit.Text;
IndexFieldName := 'AltIndex';
{$IFDEF AltMemMgr}
AltMemMgr := AltMemMgrCheckBox.Checked;
{$ENDIF}
WITH RecordLimitEdit DO
IF Text = '' THEN RecordLimit := 0
ELSE RecordLimit := StrToInt(Text);
StartTime := Now;
Execute;
Pages := Pages + [pgSearch]
FINALLY
{$IFDEF Debug}
State := [];
MakeDictionary1PhaseTwo(MakeDictionary1);
{$ENDIF}
TRY
IF TableExists(KeyViolTable1) THEN
KeyViolTable1.Open
EXCEPT
END;
Screen.Cursor := crDefault;
PhaseForm.Hide
END;
end;
procedure TMainForm.SearchBtnClick(Sender: TObject);
begin
WITH Sender AS TButton DO
BEGIN
IF (Caption = SearchBtnCaption[SearchDictionary1.SearchMode]) AND
(SearchDictionary1.State = []) THEN
TRY
FContinue := TRUE;
Caption := 'Stop';
Search
FINALLY
Caption := SearchBtnCaption[SearchDictionary1.SearchMode]
END
ELSE FContinue := FALSE
END
end;
procedure TMainForm.Search;
BEGIN
{$IFDEF Debug}
WITH MakeDictionary1 DO
BEGIN
FieldNames.Assign(SelectFldListBox.Items);
WordDelims := DelimsEdit.Text;
StrictChecking := StrictCheckingCheckBox.Checked;
IndexMode := TIndexMode(IndexModeComboBox.ItemIndex);
MinWordLen := StrToInt(MinWordLenEdit.Text);
END;
{$ENDIF}
WITH SearchDictionary1 DO
BEGIN
AnyChar := AnyCharEdit.Text[1];
NearWord := StrToInt(NearWordEdit.Text);
OneChar := OneCharEdit.Text[1];
RankMode := TRankMode(RankModeRadioGroup.ItemIndex);
RecordLimit := StrToInt(MatchRecordLimitEdit.Text);
SearchLogic := TSearchLogic(SearchLogicRadioGroup.ItemIndex);
IF CacheMemoryLimitEdit.Text <> '' THEN
MemoryLimit := StrToInt(CacheMemoryLimitEdit.Text)
ELSE
MemoryLimit := 0;
IF (SubFieldListBox.Items.Count > 0) AND
(SubFieldListBox.Items.Count < SelectFldListBox.Items.Count) THEN
SubFieldNames := SubFieldListBox.Items
ELSE
SubFieldNames.Clear;
WITH SearchComboBox DO
BEGIN
Screen.Cursor := crHourGlass;
TRY
ElapsedTimeLabel.Tag := GetTickCount;
SearchFor := Text;
Execute;
FINALLY
UpdateElapsedTime(ElapsedTimeLabel);
Screen.Cursor := crDefault;
IF (ItemIndex = -1) AND (Text <> '') THEN Items.Insert(0,Text);
IF ItemIndex > 0 THEN
BEGIN
Items.Insert(0,Items[ItemIndex]); {* This will adjust ItemIndex up 1 *}
Items.Delete(ItemIndex); {* Not ItemIndex + 1! *}
ItemIndex := 0
END;
END
END;
RecordsBtn.Caption := 'Records ' + IntToStr(RecordCount);
WordsBtn.Caption := 'Words ' + IntToStr(MatchCount);
IF (FindForm(SysUtils.UpperCase(MatchTable1.TableName)) <> NIL) AND
(RecordCount <= RecordLimit) THEN
BEGIN
CreateMatchTable(MatchTable1);
StructureTable(MatchTable1)
END
ELSE MatchTable1.Tag := 1;
WordsBtn.Enabled := MatchCount > 0;
RecordsBtn.Enabled := RecordCount > 0;
MatchTableMenuItem.Enabled := RecordsBtn.Enabled;
MatchingWordsListBox.Items.Clear;
SearchDictionary1.MatchingWords(MatchingWordsListBox.Items)
END
END;
procedure TMainForm.AddLinkBtnClick(Sender: TObject);
VAR Link : TLinkData;
List : TStrings;
i : INTEGER;
PROCEDURE DeleteLink;
BEGIN
IF FEditLink = NIL THEN EXIT;
WITH FLinkList DO
DeleteLink(IndexOf(FEditLink)); {* can invalidate other links *}
WITH TListBox(EditLinkBtn.Tag) DO Items.Delete(ItemIndex);
FEditLink := NIL;
END;
begin
Application.CreateForm(TLinkForm,LinkForm);
WITH LinkForm DO
TRY
{ SearchTable1.GetFieldNames(DataFieldComboBox.Items); }
GetNonCalcFieldNames(SearchTable1,DataFieldComboBox.Items);
WITH AliasComboBox DO
Session.GetTableNames(Items[ItemIndex],'',TRUE,FALSE,LinkTableComboBox.Items);
LinkTable.DatabaseName := SearchTable1.DatabaseName;
EditLink := FEditLink;
CASE ShowModal OF
mrOk :
BEGIN
DeleteLink;
Link := TLinkData.Create;
WITH Link DO
BEGIN
DataField := DataFieldComboBox.Text;
LinkDisplay := LinkDisplayComboBox.Text;
LinkTableName := LinkTableComboBox.Text;
LinkFieldNames := LinkFieldComboBox.Text;
LinkTable.DatabaseName := SearchTable1.DatabaseName;
List := TStringList.Create;
TRY
DisplayFieldsList(List);
FOR i := 0 TO List.Count - 1 DO
SelectFldListBox.Items.Add(JustFileName(LinkTableName) + List[I])
FINALLY
List.Free
END
END;
FLinkList.Add(Link);
Link.CreateLinkFields(SearchTable1)
END;
mrNo : DeleteLink;
ELSE FEditLink := NIL
END
FINALLY
Release
END;
IF NOT (pgBuild IN Pages) THEN
BEGIN
IF SelectFldListBox.Items.Count > 0 THEN Pages := Pages + [pgBuild];
ShowAllFieldsMenuItem.Enabled := pgBuild IN Pages
END
end;
procedure TMainForm.EditLinkBtnClick(Sender: TObject);
VAR FieldName : STRING;
Index : INTEGER;
begin
WITH TListBox(EditLinkBtn.Tag) DO FieldName := Items[ItemIndex];
Index := FLinkList.FindLinkDisplayField(FieldName,TRUE);
IF Index >= 0 THEN FEditLink := FLinkList.Items[Index];
AddLinkBtnClick(Self);
IF FEditLink <> NIL THEN
BEGIN
WITH FLinkList DO DeleteLink(IndexOf(FEditLink));
FEditLink := NIL
END;
AvailFldListBoxClick(TObject(EditLinkBtn.Tag))
end;
procedure TMainForm.AvailFldListBoxClick(Sender: TObject);
VAR Field : TField;
CanEdit : BOOLEAN;
begin
CanEdit := FALSE;
WITH Sender AS TListBox,SearchTable1 DO
IF SelCount = 1 THEN
BEGIN
Field := FindField(Items[ItemIndex]);
IF Field <> NIL THEN CanEdit := Field.Calculated
END;
EditLinkBtn.Enabled := CanEdit;
EditLinkBtn.Tag := LONGINT(Sender)
end;
procedure TMainForm.SearchTable1CalcFields(DataSet: TDataset);
VAR i,j : INTEGER;
JustName,DisplayName : STRING;
Field : TField;
begin
FOR i := 0 TO FLinkList.Count - 1 DO
WITH TLinkData(FLinkList.Items[i]),DataSet DO
BEGIN
IF NOT LinkTable.Active THEN LinkTable.Open;
IF LinkTable.FindKey([FieldByName(DataField).AsString]) THEN
BEGIN
JustName := JustFileName(LinkTable.TableName);
j := 1;
WHILE j < LENGTH(LinkDisplay) DO
BEGIN
DisplayName := ExtractFieldName(LinkDisplay,j);
Field := FindField(JustName + DisplayName);
IF Field <> NIL THEN
Field.AsString := LinkTable.FieldByname(DisplayName).AsString
END
END
END
end;
procedure TMainForm.WordsTableMenuItemClick(Sender: TObject);
begin
ViewGridForm(WordsDataSource)
end;
procedure TMainForm.MatchTableMenuItemClick(Sender: TObject);
begin
IF MatchTable1.Tag <> 0 THEN
BEGIN
MatchTable1.Tag := 0;
Screen.Cursor := crHourGlass;
TRY
SearchDictionary1.RankMode := TRankMode(RankModeRadioGroup.ItemIndex);
SearchDictionary1.RecordLimit := StrToInt(MatchRecordLimitEdit.Text);
SearchDictionary1.CreateMatchTable(MatchTable1)
FINALLY
Screen.Cursor := crDefault
END
END;
StructureTable(MatchTable1);
ViewGridForm(MatchDataSource)
end;
PROCEDURE TMainForm.StructureTable(Table : TTable);
VAR i : INTEGER;
Field : TField;
Reopen : BOOLEAN;
BEGIN
WITH Table DO
BEGIN
Reopen := Active;
Close;
FreeFields(Table);
FieldDefs.Update;
FOR i := 0 TO FieldDefs.Count - 1 DO
FieldDefs[i].CreateField(Table);
FOR i := 0 TO FLinkList.Count - 1 DO
TLinkData(FLinkList[i]).CreateLinkFields(Table);
IF NOT ShowAllFieldsMenuItem.Checked THEN
FOR i := 0 TO AvailFldListBox.Items.Count - 1 DO
BEGIN
Field := FindField(AvailFldListBox.Items[i]);
IF Field <> NIL THEN Field.Visible := FALSE
END;
IF Reopen THEN Open
END
END;
procedure TMainForm.SaveMenuItemClick(Sender: TObject);
VAR Stream : TFileStream;
Writer : TWriter;
i : INTEGER;
List : TStrings;
Save : BOOLEAN;
begin
List := TStringList.Create;
WITH SaveDialog1 DO
TRY
WITH AliasComboBox DO
Session.GetAliasParams(Items[ItemIndex],List);
SaveDialog1.InitialDir := List.Values['PATH'];
FileName := FFileName;
Save := Execute;
IF Save THEN FFileName := FileName
FINALLY
List.Free
END;
IF NOT Save THEN EXIT;
Stream := TFileStream.Create(FFileName,fmCreate);
TRY
Writer := TWriter.Create(Stream,1024);
WITH Writer DO
TRY
WriteString(FileSignature);
WriteInteger(FileVersion);
WriteBoolean(ShowAllFieldsMenuItem.Checked);
{* Table Tab *}
WITH AliasComboBox DO WriteString(Items[ItemIndex]);
WITH TableComboBox DO WriteString(Items[ItemIndex]);
WITH IndexComboBox DO WriteString(Items[ItemIndex]);
FLinkList.Write(Writer);
WriteInteger(SelectFldListBox.Items.Count);
FOR i := 0 TO SelectFldListBox.Items.Count - 1 DO
WriteString(SelectFldListBox.Items[i]);
{* Build Tab *}
WriteString(BuildTimeLabel.Caption);
WriteString(WordCountLabel.Caption);
WriteString(MemUsedLabel.Caption);
WriteString(MaxMemLabel.Caption);
WriteString(DBSizeLabel.Caption);
WriteString(MBSizeLabel.Caption);
WriteString(CompressionLabel.Caption);
WriteString(WordsEdit.Text);
WriteString(KeyViolEdit.Text);
WriteBoolean(FileCompressionCheckBox.Checked);
WriteString(DelimsEdit.Text);
WriteInteger(IndexModeComboBox.ItemIndex);
WriteBoolean(StrictCheckingCheckBox.Checked);
WriteString(MinWordLenEdit.Text);
WriteString(RecordLimitEdit.Text);
WriteInteger(MemoryComboBox.ItemIndex);
WriteBoolean(AltMemMgrCheckBox.Checked);
{* Search Tab *}
WriteString(SearchComboBox.Text);
WriteString(WordsBtn.Caption);
WriteString(RecordsBtn.Caption);
WriteString(ElapsedTimeLabel.Caption);
WriteInteger(SearchLogicRadioGroup.ItemIndex);
WriteInteger(SearchModeRadioGroup.ItemIndex);
WriteInteger(RankModeRadioGroup.ItemIndex);
{ SubFields not saved }
WriteString(CacheMemoryLimitEdit.Text);
WriteInteger(MatchingWordsListBox.Items.Count);
FOR i := 0 TO MatchingWordsListBox.Items.Count - 1 DO
WriteString(MatchingWordsListBox.Items[i]);
WriteString(MatchedEdit.Text);
WriteString(MatchRecordLimitEdit.Text);
WriteString(AnyCharEdit.Text);
WriteString(OneCharEdit.Text);
WriteString(NearWordEdit.Text);
{* Reserved for future use *}
FOR i := 0 TO 3 DO WriteString('~~~');
FINALLY
Free
END
FINALLY
Stream.Free
END
end;
procedure TMainForm.OpenMenuItemClick(Sender: TObject);
VAR Stream : TFileStream;
Reader : TReader;
Count,i,j : INTEGER;
List : TStrings;
Version : LONGINT;
Open : BOOLEAN;
begin
List := TStringList.Create;
WITH OpenDialog1 DO
TRY
Session.GetAliasParams(AliasComboBox.Text,List);
InitialDir := List.Values['PATH'];
Open := Execute;
IF Open THEN FFileName := FileName
FINALLY
List.Free
END;
IF NOT Open THEN EXIT;
Stream := TFileStream.Create(FFileName,fmOpenRead);
TRY
Reader := TReader.Create(Stream,1024);
WITH Reader DO
TRY
IF ReadString <> FileSignature THEN
RAISE EDictionary.Create('Invalid file format!');
Version := ReadInteger;
ShowAllFieldsMenuItem.Checked := NOT ReadBoolean;
ShowAllFieldsMenuItemClick(ShowAllFieldsMenuItem);
{* Table Tab *}
SetComboBoxIndex(AliasComboBox,ReadString);
AliasComboBoxChange(NIL);
SetComboboxIndex(TableComboBox,ReadString);
TableComboBoxChange(NIL);
SetComboBoxIndex(IndexComboBox,ReadString);
IndexComboboxChange(NIL);
FLinkList.Read(Reader);
FOR i := 0 TO FLinkList.Count - 1 DO
WITH TLinkData(FLinkList.Items[i]) DO
BEGIN
List := TStringList.Create;
TRY
DisplayFieldsList(List);
FOR j := 0 TO List.Count - 1 DO
AvailFldListBox.Items.Add(JustFileName(LinkTableName) + List[j])
FINALLY
List.Free
END;
CreateLinkFields(SearchTable1)
END;
Count := ReadInteger;
FOR i := 1 TO Count DO
BEGIN
j := AvailFldListBox.Items.IndexOf(ReadString);
IF j >= 0 THEN AvailFldListBox.Selected[j] := TRUE
END;
MoveRightBtnClick(NIL);
{* Build Tab *}
BuildTimeLabel.Caption := ReadString;
WordCountLabel.Caption := ReadString;
MemUsedLabel.Caption := ReadString;
MaxMemLabel.Caption := ReadString;
DBSizeLabel.Caption := ReadString;
MBSizeLabel.Caption := ReadString;
CompressionLabel.Caption := ReadString;
WordsEdit.Text := ReadString;
KeyViolEdit.Text := ReadString;
FileCompressionCheckBox.Checked := ReadBoolean;
DelimsEdit.Text := ReadString;
IndexModeComboBox.ItemIndex := ReadInteger;
StrictCheckingCheckBox.Checked := ReadBoolean;
MinWordLenEdit.Text := ReadString;
RecordLimitEdit.Text := ReadString;
MemoryComboBox.ItemIndex := ReadInteger;
AltMemMgrCheckBox.Checked := ReadBoolean;
{* Search Tab *}
SearchComboBox.Text := ReadString;
WordsBtn.Caption := ReadString;
RecordsBtn.Caption := ReadString;
ElapsedTimeLabel.Caption := ReadString;
SearchLogicRadioGroup.ItemIndex := ReadInteger;
SearchModeRadioGroup.ItemIndex := ReadInteger;
RankModeRadioGroup.ItemIndex := ReadInteger;
CacheMemoryLimitEdit.Text := ReadString;
MatchingWordsListBox.Items.Clear;
Count := ReadInteger;
FOR i := 0 TO Count - 1 DO
MatchingWordsListBox.Items.Add(ReadString);
MatchedEdit.Text := ReadString;
MatchRecordLimitEdit.Text := ReadString;
AnyCharEdit.Text := ReadString;
OneCharEdit.Text := ReadString;
NearWordEdit.Text := ReadString;
{* Reserved for future use *}
FOR i := 0 TO 3 DO ReadString;
FINALLY
Free
END
FINALLY
Stream.Free
END;
{$IFDEF Debug}
SearchTable1.Open;
MatchTable1.DatabaseName := SearchTable1.DatabaseName;
MatchTable1.TableName := MatchedEdit.Text;
KeyViolTable1.TableName := AliasToPath(KeyViolEdit.Text);
WordsTable1.DatabaseName := SearchTable1.DatabaseName;
WordsTable1.TableName := WordsEdit.Text;
WordsTable1.IndexFieldNames := 'Word';
WordsTable1.Exclusive := TRUE;
WordsTable1.Open;
Pages := Pages + [pgSearch]
{$ENDIF}
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
FLinkList.Free
end;
procedure TMainForm.WordsTable1AfterOpen(DataSet: TDataset);
begin
DataSet.Tag := GetRecordSize(DataSet);
WordsTableMenuItem.Enabled := TRUE
end;
procedure TMainForm.AnyCharEditExit(Sender: TObject);
begin
WITH SearchBtn DO
BEGIN
Enabled := LENGTH((Sender AS TEdit).Text) = 1;
IF NOT Enabled THEN
BEGIN
MessageDlg('Cannot search without valid wildcards',mtError,[mbOk],0);
(Sender AS TEdit).SetFocus
END
END
end;
procedure TMainForm.IntegerEditExit(Sender: TObject);
PROCEDURE Error;
BEGIN
WITH Sender AS TEdit DO
BEGIN
IF Tag = 0 THEN
MessageDlg('Value must be a positive integer or blank',mtError,[mbOk],0)
ELSE
MessageDlg('Value must be in the range ' +
IntToStr(LOWORD(Tag)) + ' - ' + IntToStr(HIWORD(Tag)),
mtError,[mbOk],0);
SetFocus
END
END;
begin
WITH Sender AS TEdit DO
TRY
IF Tag = 0 THEN
IF (Text <> '') AND (StrToInt(Text) < 0) THEN Error
ELSE
ELSE
IF (StrToInt(Text) > HIWORD(Tag)) OR
(StrToInt(Text) < LOWORD(Tag)) THEN Error
EXCEPT
ON EConvertError DO Error
END
end;
procedure TMainForm.IndexModeComboBoxChange(Sender: TObject);
begin
WITH Sender AS TComboBox,MakeDictionary1 DO
BEGIN
DataSource := SearchDataSource;
StrictChecking := StrictCheckingCheckBox.Checked;
TRY
IndexMode := TIndexMode(ItemIndex)
EXCEPT
ON EDictionary DO
ItemIndex := ORD(SafeIndexMode(SearchTable1))
END
END
end;
procedure TMainForm.ShowAllFieldsMenuItemClick(Sender: TObject);
VAR i : INTEGER;
begin
WITH SearchTable1,Sender AS TMenuItem DO
BEGIN
Checked := NOT Checked;
FOR i := 0 TO FieldCount - 1 DO
WITH Fields[i] DO
Visible := Checked OR (SelectFldListBox.Items.IndexOf(FieldName) <> -1)
END
end;
procedure TMainForm.SearchTable1AfterOpen(DataSet: TDataset);
VAR F : TForm;
begin
SearchTableMenuItem.Enabled := TRUE;
F := FindForm('Search Table');
IF F <> NIL THEN F.Caption := UpperCase(TTable(DataSet).TableName)
end;
procedure TMainForm.SearchTable1BeforeClose(DataSet: TDataset);
VAR F : TForm;
begin
SearchTableMenuItem.Enabled := FALSE;
F := FindForm(UpperCase(TTable(DataSet).TableName));
IF F <> NIL THEN F.Caption := 'Search Table'
end;
procedure TMainForm.WordsTable1BeforeClose(DataSet: TDataset);
begin
WordsTableMenuItem.Enabled := FALSE;
end;
procedure TMainForm.MatchTable1AfterOpen(DataSet: TDataset);
begin
MatchTableMenuItem.Enabled := TRUE;
RecordsBtn.Enabled := TRUE
end;
procedure TMainForm.MatchTable1BeforeClose(DataSet: TDataset);
begin
MatchTableMenuItem.Enabled := FALSE;
RecordsBtn.Enabled := FALSE
end;
procedure TMainForm.SaveAsMenuItemClick(Sender: TObject);
begin
FFilename := 'LINK1.RDM';
SaveMenuItemClick(Sender)
end;
procedure TMainForm.ExitMenuItemClick(Sender: TObject);
begin
Application.Terminate
end;
procedure TMainForm.About1Click(Sender: TObject);
var F : TForm;
begin
Application.CreateForm(TAboutForm,F);
F.ShowModal
end;
procedure TMainForm.TabbedNotebook1Change(Sender: TObject; NewTab: Integer;
var AllowChange: Boolean);
begin
AllowChange := TPage(NewTab) IN Pages;
end;
procedure TMainForm.WordsEditExit(Sender: TObject);
begin
WITH WordsTable1 DO
IF Active AND (CompareText(WordsEdit.Text,TableName) <> 0) THEN
BEGIN
Close;
DeleteTable;
Pages := Pages - [pgSearch]
END
end;
procedure TMainForm.MatchedEditExit(Sender: TObject);
begin
WITH MatchTable1 DO
IF Active AND (CompareText(WordsEdit.Text,TableName) <> 0) THEN
BEGIN
Close;
DeleteTable
END
end;
procedure TMainForm.NewMenuItemClick(Sender: TObject);
begin
INC(FFileNo);
SetDefaults1;
SetDefaults2;
TabbedNotebook1.PageIndex := 0;
end;
procedure TMainForm.KeyViolTable1AfterOpen(DataSet: TDataset);
begin
KeyViolTableMenuItem.Enabled := TRUE
end;
procedure TMainForm.KeyViolTable1BeforeClose(DataSet: TDataset);
begin
KeyViolTableMenuItem.Enabled := FALSE
end;
procedure TMainForm.KeyViolTableMenuItemClick(Sender: TObject);
begin
ViewGridForm(KeyViolDataSource)
end;
procedure TMainForm.KeyViolEditExit(Sender: TObject);
begin
WITH KeyViolTable1 DO
IF Active AND (CompareText(KeyViolEdit.Text,TableName) <> 0) THEN
BEGIN
Close;
DeleteTable
END
end;
procedure TMainForm.ShowHintsMenuItemClick(Sender: TObject);
begin
WITH ShowHintsMenuItem DO
BEGIN
Checked := NOT Checked;
Application.ShowHint := Checked
END
end;
PROCEDURE TMainForm.UpdateCacheStats;
BEGIN
WITH SearchDictionary1 DO
BEGIN
DiskReadsLabel.Caption := Format('%8.0n',[DiskReads + 0.001]);
CacheReadsLabel.Caption := Format('%8.0n',[CacheReads + 0.001]);
SourceReadsLabel.Caption := Format('%8.0n',[SourceReads + 0.001]);
MemoryUsageLabel.Caption := Format('%8.0n',[MemoryUsage + 0.001])
END
END;
procedure TMainForm.SearchDictionary1Search(Sender: TObject);
begin
UpdateElapsedTime(ElapsedTimeLabel);
IF (SearchOptionsRadioGroup.ItemIndex = 3) OR
(dsDone IN SearchDictionary1.State) THEN UpdateCacheStats;
Application.ProcessMessages;
IF NOT FContinue THEN
WITH SearchDictionary1 DO
State := State + [dsAbort]
end;
procedure TMainForm.Contents1Click(Sender: TObject);
begin
Application.HelpCommand(HELP_CONTENTS,0)
end;
procedure TMainForm.WordsBtnClick(Sender: TObject);
begin
SearchOptionsRadioGroup.ItemIndex := 5
end;
procedure TMainForm.RecordsBtnClick(Sender: TObject);
begin
MatchTableMenuItemClick(Sender)
end;
procedure TMainForm.SearchComboBoxChange(Sender: TObject);
begin
WITH Sender AS TComboBox DO
BEGIN
SearchBtn.Enabled := Text <> '';
SearchBtn.Default := SearchBtn.Enabled;
{ SearchPrevBtn.Default := NOT SearchBtn.Enabled }
END
end;
procedure TMainForm.SearchOptionsRadioGroupClick(Sender: TObject);
begin
WITH Sender AS TRadioGroup DO
SearchNotebook.PageIndex := ItemIndex
end;
procedure TMainForm.BuildOptionsRadioGroupClick(Sender: TObject);
begin
WITH Sender AS TRadioGroup DO
BEGIN
BuildNotebook.PageIndex := ItemIndex;
{ CASE ItemIndex OF
0 : WordsEdit.SetFocus;
1 : DelimsEdit.SetFocus;
2 : IndexModeComboBox.SetFocus;
3 : MinWordLenEdit.SetFocus
END }
END
end;
procedure TMainForm.SubFieldsAddAllBtnClick(Sender: TObject);
begin
WITH SubFieldListBox.Items DO
BEGIN
Clear;
Assign(SelectFldListBox.Items)
END
end;
procedure TMainForm.SubFieldsRemoveBtnClick(Sender: TObject);
begin
WITH SubFieldListBox DO
IF ItemIndex <> -1 THEN Items.Delete(ItemIndex)
end;
PROCEDURE TMainForm.SetPages(Value : TPages);
BEGIN
IF Value <> FPages THEN
BEGIN
FPages := Value;
CASE TPage(TabbedNotebook1.PageIndex) OF
pgTable : NextBtn.Enabled := pgTable IN Pages;
pgBuild : NextBtn.Enabled := pgBuild IN Pages
END
END
END;
procedure TMainForm.SubFieldListBoxDblClick(Sender: TObject);
begin
WITH Sender AS TListBox,Items DO
IF Count > 1 THEN Delete(ItemIndex)
end;
procedure TMainForm.ResetBtnClick(Sender: TObject);
begin
SearchDictionary1.ResetStats;
UpdateCacheStats
end;
procedure TMainForm.FlushBtnClick(Sender: TObject);
begin
SearchDictionary1.FlushCache;
UpdateCacheStats
end;
procedure TMainForm.TabbedNotebook1Click(Sender: TObject);
begin
CASE TPage(TabbedNotebook1.PageIndex) OF
pgIntroduction : BEGIN
PrevBtn.Enabled := FALSE;
NextBtn.Enabled := TRUE;
BuildBtn.Visible := FALSE;
ActiveControl := NextBtn;
END;
pgTable : BEGIN
SearchDictionary1.FlushCache;
PrevBtn.Enabled := TRUE;
NextBtn.Enabled := pgBuild IN Pages;
BuildBtn.Visible := FALSE;
ActiveControl := AliasComboBox;
END;
pgBuild : BEGIN
SearchDictionary1.FlushCache;
PrevBtn.Enabled := TRUE;
NextBtn.Enabled := pgSearch IN Pages;
BuildBtn.Visible := TRUE;
ActiveControl := BuildBtn;
END;
pgSearch : BEGIN
SearchDictionary1.FlushCache;
PrevBtn.Enabled := TRUE;
NextBtn.Enabled := FALSE;
BuildBtn.Visible := FALSE;
ActiveControl := SearchComboBox;
SubFieldsAddAllBtnClick(NIL);
END;
END
end;
procedure TMainForm.SearchModeRadioGroupClick(Sender: TObject);
begin
WITH Sender AS TRadioGroup DO
SearchDictionary1.SearchMode := TSearchMode(ItemIndex);
SearchBtn.Caption := SearchBtnCaption[SearchDictionary1.SearchMode];
SearchBtn.Hint := SearchBtnHint[SearchDictionary1.SearchMode]
end;
procedure TMainForm.MakeDictionary1PhaseOne(Sender: TObject);
VAR CurrentTics : LONGINT;
{$IFDEF Debug}
CS : TCacheStats;
{$IFDEF WIN32}
MS : TMemoryStatus;
{$ENDIF}
{$ENDIF}
BEGIN
CurrentTics := GetTickCount;
WITH TMakeDictionary(Sender), PhaseForm DO
BEGIN
IF State = [dsPhaseOne,dsStart] THEN
BEGIN
Gauge.MinValue := 0;
IF RecordLimit = 0 THEN
Gauge.MaxValue := SearchTable1.RecordCount
ELSE
Gauge.MaxValue := MinLong(RecordLimit,SearchTable1.RecordCount);
Gauge.Progress := 0;
FLastUpd := CurrentTics;
Caption := 'Phase One';
CanExpand := FALSE;
Show;
SetFocus;
DBSizeLabel.Caption := '';
MBSizeLabel.Caption := '';
CompressionLabel.Caption := '';
END;
IF (CurrentTics - FLastUpd > RefreshTics) OR (dsDone IN State) THEN
BEGIN
FLastUpd := CurrentTics;
Gauge.Progress := RecordNo;
Self.BuildTimeLabel.Caption := FormatDateTime(' hh:nn:ss',Now - StartTime);
Self.MemUsedLabel.Caption := Format('%10.0n',[MemoryUsage + 0.001]);
Self.MaxMemLabel.Caption := Format('%10.0n',[MaxMemUsed + 0.001]);
Self.WordCountLabel.Caption := Format('%10.0n',[CacheCount - OmitList.Count + 0.001]);
Application.ProcessMessages;
IF NOT PhaseForm.Visible THEN State := State + [dsAbort]
END;
{$IFDEF Debug}
IF dsCompress IN State THEN
BEGIN
{$IFDEF WIN32}
MS.dwLength := SIZEOF(MS);
GlobalMemoryStatus(MS);
DBSizelabel.Caption := IntToStr(MS.dwTotalVirtual - MS.dwAvailVirtual);
{$ENDIF}
GetCacheStats(CS);
WITH CS,MBSizeLabel DO
BEGIN
IF dsStart IN State THEN Font.Color := clRed
ELSE Font.Color := clBlack;
Caption := IntToStr(Compressed) + ':' + IntToStr(Uncompressed)
END;
WITH CS,CompressionLabel DO
BEGIN
IF dsStart IN State THEN Font.Color := clRed
ELSE Font.Color := clBlack;
Caption := IntToStr(LRU) + ':' + IntToStr(CompressLRU)
END;
Application.ProcessMessages;
IF NOT PhaseForm.Visible THEN State := State + [dsAbort]
END
{$ENDIF}
END
end;
procedure TMainForm.MakeDictionary1PhaseTwo(Sender: TObject);
VAR CurrentTics : LONGINT;
BEGIN
CurrentTics := GetTickCount;
WITH TMakeDictionary(Sender), PhaseForm DO
BEGIN
IF dsStart IN State THEN
BEGIN
Caption := 'Phase Two';
Gauge.MinValue := 0;
Gauge.MaxValue := CacheCount - OmitList.Count;
Gauge.Progress := 0;
FLastUpd := CurrentTics;
IF NOT FileCompression THEN CompressionLabel.Caption := ' N/A'
END;
IF (CurrentTics - FLastUpd > RefreshTics) OR (dsDone IN State) OR (DiskInserts = Gauge.MaxValue) THEN
BEGIN
FLastUpd := CurrentTics;
Gauge.Progress := DiskInserts;
Self.BuildTimeLabel.Caption := FormatDateTime(' hh:nn:ss',Now - StartTime);
Self.MemUsedLabel.Caption := Format('%10.0n',[MemoryUsage + 0.001]);
Self.MaxMemLabel.Caption := Format('%10.0n',[MaxMemUsed + 0.001]);
Self.DBSizeLabel.Caption := Format('%10.0n',[DiskInserts * WordsTable1.Tag + 0.001]);
Self.MBSizeLabel.Caption := Format('%10.0n',[BlobBytesWritten + 0.001]);
IF (DiskInserts > 0) AND FileCompression THEN
Self.CompressionLabel.Caption :=
Format('%9.1n%%',[(1.0 - BlobBytesWritten / (DiskInserts * ((IndexRange + 8) SHR 3))) * 100]);
Application.ProcessMessages;
IF NOT PhaseForm.Visible THEN State := State + [dsAbort]
END
END
end;
end.